package cn.itcast.shiro;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.apache.shiro.crypto.hash.Md5Hash;

public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        // 1 获取安全数据的密码
        String data_password = (String)info.getCredentials();
        // 2 获取页面数据
        UsernamePasswordToken uPToken=(UsernamePasswordToken)token;
        char[] password = uPToken.getPassword();
        String ym_password=new String(password);
        //3 将页面数据做加密(shiro加密)
        Md5Hash md5Hash = new Md5Hash(ym_password, uPToken.getUsername(), 1);
        String s = md5Hash.toString();
        System.out.println(s);
        return data_password.equals(s);
    }
}
